package com.free.event;

import javax.swing.JOptionPane;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

/**
 * <p>
 * Title: Eclipse Plugin Development
 * </p>
 * <p>
 * Description: Free download
 * </p>
 * <p>
 * mail: ganshm@gmail.com
 * </p>
 */

public class SelectonListenerExample
{
    
    public static void main(String[] args)
    {
        Display display = new Display();
        
        // Create the main window
        final Shell mainShell = new Shell(display);
        
        // Add a button and a listener to the child shell
        Button button = new Button(mainShell, SWT.PUSH);
        button.setText("Close Me!");
        button.setBounds(10, 10, 100, 30);
        // 添加选择组件事件
        button.addSelectionListener(new SelectionListener()
        {
            public void widgetSelected(SelectionEvent event)
            {
                // When the button is pressed, close the child shell
                System.out.println("select button");
//				jpa
                JOptionPane.showMessageDialog(null, "OK");
//				mainShell.close();
            }
            
            public void widgetDefaultSelected(SelectionEvent e)
            {
                // 不执行任何操作
            }
        });
        
        Button button1 = new Button(mainShell, SWT.PUSH);
        button1.setText("Close Me11!");
        button1.setBounds(100, 100, 100, 30);
        // 添加选择组件事件
        button1.addSelectionListener(new SelectionListener()
        {
            public void widgetSelected(SelectionEvent event)
            {
                // When the button is pressed, close the child shell
                System.out.println("select button");
//				jpa
                JOptionPane.showMessageDialog(null, "OK1");
//				mainShell.close();
            }
            
            public void widgetDefaultSelected(SelectionEvent e)
            {
                // 不执行任何操作
            }
        });
        
        // Open the shells
        mainShell.open();
        
        while (!mainShell.isDisposed())
        {
            if (!display.readAndDispatch())
            {
                display.sleep();
            }
        }
        display.dispose();
    }
}
